<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=2"><meta name="theme-color" content="#FFF"><meta name="baidu-site-verification" content="code-DvHFUp3jdk"><meta name="baidu-site-verification" content="code-eHnRZZHAeP"><meta name="baidu-site-verification" content="code-EmlZBboqEW"><meta name="baidu-site-verification" content="code-Hf9ZXEHZ41"><meta name="360-site-verification" content="941073b91e9afaf02748ba000ba47e80"><meta name="360-site-verification" content="010bd45f0d523ce46f298dd597ef0289"><meta name="sogou_site_verification" content="hlLPNfmIjv"><meta name="sogou_site_verification" content="y3La2dTB20"><meta name="msvalidate.01" content="03829B28CC46A7AA4B5503897F475BA1"><script>!function(){var s="https://s.ssl.qhres2.com/ssl/ab77b6ea7f3fbf79.js";document.write('<script src="'+s+'" id="sozz"><\/script>')}()</script><script>!function(t,e,c,n,r,a,s){t[c]=t[c]||function(){(t[c].q=t[c].q||[]).push(arguments)},a=e.createElement(n),a.async=1,a.src="https://www.clarity.ms/tag/"+r+"?ref=bwt",s=e.getElementsByTagName(n)[0],s.parentNode.insertBefore(a,s)}(window,document,"clarity","script","8xwpfccwj2")</script><script>var _hmt=_hmt||[];!function(){var e=document.createElement("script");e.src="https://hm.baidu.com/hm.js?1d318b0509ca0909017253ed6f659ae4";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}()</script><script>var _hmt=_hmt||[];!function(){var e=document.createElement("script");e.src="https://hm.baidu.com/hm.js?aea6c1471d6299bdd1c87a0836f18675";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}()</script><script>var _hmt=_hmt||[];!function(){var e=document.createElement("script");e.src="https://hm.baidu.com/hm.js?498ca413655655a62058d6b5d7c62786";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}()</script><script>var _hmt=_hmt||[];!function(){var e=document.createElement("script");e.src="https://hm.baidu.com/hm.js?e19e8161e13f718806b79f49240583b4";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}()</script><link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png"><link rel="icon" type="image/ico" sizes="32x32" href="/images/favicon.ico"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="google-site-verification" content="UA-139249935-1"><meta name="baidu-site-verification" content="cOtBu9CtTEIuwJeN"><link rel="alternate" type="application/rss+xml" title="了尘兰若的小坑" href="https://liaochenlanruo.gitee.io/rss.xml"><link rel="alternate" type="application/atom+xml" title="了尘兰若的小坑" href="https://liaochenlanruo.gitee.io/atom.xml"><link rel="alternate" type="application/json" title="了尘兰若的小坑" href="https://liaochenlanruo.gitee.io/feed.json"><link rel="stylesheet" href="//fonts.googleapis.com/css?family=Mulish:300,300italic,400,400italic,700,700italic%7CFredericka%20the%20Great:300,300italic,400,400italic,700,700italic%7CNoto%20Serif%20JP:300,300italic,400,400italic,700,700italic%7CNoto%20Serif%20SC:300,300italic,400,400italic,700,700italic%7CInconsolata:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext"><link rel="stylesheet" href="/css/app.css?v=0.2.5"><meta name="keywords" content="扩增子,SY179,R语言"><link rel="canonical" href="https://liaochenlanruo.gitee.io/post/fccc.html"><title>扩增子可视化专题 - 可视化 | ResearchGo = 了尘兰若的小坑 = liaochenlanruo</title><meta name="generator" content="Hexo 5.4.0"></head><body itemscope itemtype="http://schema.org/WebPage"><div id="loading"><div class="cat"><div class="body"></div><div class="head"><div class="face"></div></div><div class="foot"><div class="tummy-end"></div><div class="bottom"></div><div class="legs left"></div><div class="legs right"></div></div><div class="paw"><div class="hands left"></div><div class="hands right"></div></div></div></div><div id="container"><header id="header" itemscope itemtype="http://schema.org/WPHeader"><div class="inner"><div id="brand"><div class="pjax"><h1 itemprop="name headline">扩增子可视化专题</h1><div class="meta"><span class="item" title="Created: 2021-09-15 11:23:28"><span class="icon"><i class="ic i-calendar"></i> </span><span class="text">Posted on</span> <time itemprop="dateCreated datePublished" datetime="2021-09-15T11:23:28+08:00">2021-09-15</time> </span><span class="item" title="Symbols count in article"><span class="icon"><i class="ic i-pen"></i> </span><span class="text">Symbols count in article</span> <span>11k</span> <span class="text">words</span> </span><span class="item" title="Reading time"><span class="icon"><i class="ic i-clock"></i> </span><span class="text">Reading time</span> <span>10 mins.</span></span></div></div></div><nav id="nav"><div class="inner"><div class="toggle"><div class="lines" aria-label="Toggle navigation bar"><span class="line"></span> <span class="line"></span> <span class="line"></span></div></div><ul class="menu"><li class="item title"><a href="/" rel="start">ResearchGo</a></li></ul><ul class="right"><li class="item theme"><i class="ic i-sun"></i></li><li class="item search"><i class="ic i-search"></i></li></ul></div></nav></div><div id="imgs" class="pjax"><img src="https://fastly.jsdelivr.net/gh/liaochenlanruo/cdn@master/img/custom/bgs/thumb_55.webp"></div></header><div id="waves"><svg class="waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"><defs><path id="gentle-wave" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z"/></defs><g class="parallax"><use xlink:href="#gentle-wave" x="48" y="0"/><use xlink:href="#gentle-wave" x="48" y="3"/><use xlink:href="#gentle-wave" x="48" y="5"/><use xlink:href="#gentle-wave" x="48" y="7"/></g></svg></div><main><div class="inner"><div id="main" class="pjax"><div class="article wrap"><div class="breadcrumb" itemscope itemtype="https://schema.org/BreadcrumbList"><i class="ic i-home"></i> <span><a href="/">Home</a></span><i class="ic i-angle-right"></i> <span class="current" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="/categories/Visualization/" itemprop="item" rel="index" title="In 可视化"><span itemprop="name">可视化</span></a><meta itemprop="position" content="1"></span></div><article itemscope itemtype="http://schema.org/Article" class="post block" lang="en"><link itemprop="mainEntityOfPage" href="https://liaochenlanruo.gitee.io/post/fccc.html"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="image" content="/images/head.jpg"><meta itemprop="name" content="Hualin Liu"><meta itemprop="description" content="liaochenlanruo, 分享微生物生物信息学分析方法，欢迎加入QQ群交流945751012，不接受群内广告！"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="了尘兰若的小坑"></span><div class="body md" itemprop="articleBody"><div class="gallery" itemscope itemtype="http://schema.org/ImageGallery"><img data-src="https://fastly.jsdelivr.net/gh/liaochenlanruo/cdn@master/img/custom/bgs/thumb_55.webp" itemprop="contentUrl"></div><p>扩增子分析较常用的软件是 QIIME2，然而其生成的图并不美观，且无法下载，是不可能够达到发表要求的，因此需要我们通过其他方法将 QIIME2 生成的数据结果进行可视化。本文将记录相关的分析方法和示例。</p><h1 id="准备数据"><a class="anchor" href="#准备数据">#</a> 准备数据</h1><ul><li>特征表（Feature table），或者叫做 OTU 表，本教程中文件名为<strong> feature-table.tsv</strong>。该文件可由 QIIME2 生成，由 biome 格式转换而来。</li></ul><figure class="highlight tex"><figcaption data-lang="TeX"></figcaption><table><tr><td data-num="1"></td><td><pre>F01	F02	F03	F04	F05	F06	H2_1	H2_2	H2_3	H2_4	H2_5	H2_6	I1_1	I1_2	I1_3	I1_4	I1_5	I1_6</pre></td></tr><tr><td data-num="2"></td><td><pre>3733c766539aba5e3e8f964a5ba39048	0.0	0.0	0.0	0.0	0.0	0.0	0.0	6.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0</pre></td></tr><tr><td data-num="3"></td><td><pre>547715c94c5b0c7ba2049658f732397b	0.0	0.0	0.0	6.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0</pre></td></tr><tr><td data-num="4"></td><td><pre>708c69ff1252447c0709333304cd9bed	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	5.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0</pre></td></tr><tr><td data-num="5"></td><td><pre>344ee69a9e51ffac2811294d3f04833d	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	7.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0</pre></td></tr><tr><td data-num="6"></td><td><pre>d2e467b7867f49c25caaacdea5c7eb43	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	18.0	0.0	0.0	0.0	0.0</pre></td></tr><tr><td data-num="7"></td><td><pre>4adc9b2b0866f620425d07d3ff7ca7e2	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	8.0	0.0	0.0	0.0	0.0</pre></td></tr><tr><td data-num="8"></td><td><pre>0ffcdef70b9c1436126ba32d7a40d961	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	31.0	0.0	0.0	0.0</pre></td></tr><tr><td data-num="9"></td><td><pre>7170ce6c7520acc3c13189478aea54a8	53.0	0.0	0.0	0.0	0.0	0.0	37.0	25.0	0.0	0.0	0.0	0.0	23.0	21.0	0.0	0.0	0.0	0.0</pre></td></tr><tr><td data-num="10"></td><td><pre>b624986630f3d33fbe0a21e66c46d1a5	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	9.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0</pre></td></tr><tr><td data-num="11"></td><td><pre>78305c3f5955043aba7de952c78859c9	0.0	0.0	22.0	57.0	73.0	55.0	0.0	0.0	0.0	82.0	73.0	0.0	0.0	0.0	43.0	132.0	82.0	95.0</pre></td></tr><tr><td data-num="12"></td><td><pre>60d9992b10f6dd4da4dc53826b7433f5	0.0	0.0	0.0	0.0	45.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0</pre></td></tr><tr><td data-num="13"></td><td><pre>33468988848349138af5cb1c23b550f2	0.0	2.0	11.0	12.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0	0.0</pre></td></tr></table></figure><ul><li>样本元数据（Metadata），本教程中文件名为<strong> sample-metadata.tsv</strong>。该文件由分析者自己准备，用于描述各个样本的特征。</li></ul><figure class="highlight tex"><figcaption data-lang="TeX"></figcaption><table><tr><td data-num="1"></td><td><pre>ID	Samples	Layer	Depth	Depth2	Location	Position	Site</pre></td></tr><tr><td data-num="2"></td><td><pre>F01	F01	0-5	5	05 cmbsf	Turn	Upstream	F</pre></td></tr><tr><td data-num="3"></td><td><pre>F02	F02	5-9	10	10 cmbsf	Turn	Upstream	F</pre></td></tr><tr><td data-num="4"></td><td><pre>F03	F03	9-13	15	15 cmbsf	Turn	Upstream	F</pre></td></tr><tr><td data-num="5"></td><td><pre>F04	F04	13-17	15	15 cmbsf	Turn	Upstream	F</pre></td></tr><tr><td data-num="6"></td><td><pre>F05	F05	17-22	20	20 cmbsf	Turn	Upstream	F</pre></td></tr><tr><td data-num="7"></td><td><pre>F06	F06	22-26	25	25 cmbsf	Turn	Upstream	F</pre></td></tr><tr><td data-num="8"></td><td><pre>H2_1	H2_1	0-5	5	05 cmbsf	Left	Upstream	H2</pre></td></tr><tr><td data-num="9"></td><td><pre>H2_2	H2_2	5-10	10	10 cmbsf	Left	Upstream	H2</pre></td></tr><tr><td data-num="10"></td><td><pre>H2_3	H2_3	10-15	15	15 cmbsf	Left	Upstream	H2</pre></td></tr><tr><td data-num="11"></td><td><pre>H2_4	H2_4	15-20	20	20 cmbsf	Left	Upstream	H2</pre></td></tr><tr><td data-num="12"></td><td><pre>H2_5	H2_5	20-25	25	25 cmbsf	Left	Upstream	H2</pre></td></tr><tr><td data-num="13"></td><td><pre>H2_6	H2_6	25-29	30	30 cmbsf	Left	Upstream	H2</pre></td></tr><tr><td data-num="14"></td><td><pre>I1_1	I1_1	0-5	5	05 cmbsf	Left	Upstream	I1</pre></td></tr><tr><td data-num="15"></td><td><pre>I1_2	I1_2	5-10	10	10 cmbsf	Left	Upstream	I1</pre></td></tr><tr><td data-num="16"></td><td><pre>I1_3	I1_3	10-15	15	15 cmbsf	Left	Upstream	I1</pre></td></tr><tr><td data-num="17"></td><td><pre>I1_4	I1_4	15-20	20	20 cmbsf	Left	Upstream	I1</pre></td></tr><tr><td data-num="18"></td><td><pre>I1_5	I1_5	20-25	25	25 cmbsf	Left	Upstream	I1</pre></td></tr><tr><td data-num="19"></td><td><pre>I1_6	I1_6	25-29	30	30 cmbsf	Left	Upstream	I1</pre></td></tr></table></figure><ul><li>分类信息，本教程中文件名为<strong> taxonomy.tsv</strong>。该文件可由 QIIME2 生成。</li></ul><figure class="highlight tex"><figcaption data-lang="TeX"></figcaption><table><tr><td data-num="1"></td><td><pre>Feature ID	Taxon	Confidence</pre></td></tr><tr><td data-num="2"></td><td><pre>9e24eb7a415db9a59586d17d0f49cbea	Archaea;Asgardarchaeota;Lokiarchaeia	0.9999999998216045</pre></td></tr><tr><td data-num="3"></td><td><pre>2a1d71d9fca92f9b3fc8f3126db076d0	Bacteria;Proteobacteria;Gammaproteobacteria;Pseudomonadales;Pseudomonadaceae;Pseudomonas	0.9881304182870394</pre></td></tr><tr><td data-num="4"></td><td><pre>5d89868f1a1db1bc0b153eca96bbf7fd	Archaea;Crenarchaeota;Nitrososphaeria;Nitrosopumilales;Nitrosopumilaceae	0.9999999999859067</pre></td></tr><tr><td data-num="5"></td><td><pre>cc957f2e853493d72875a6528ca83435	Archaea;Crenarchaeota;Nitrososphaeria;Nitrosopumilales;Nitrosopumilaceae	0.9999999999854506</pre></td></tr><tr><td data-num="6"></td><td><pre>5179960239613d4c220e889075c6773e	Archaea;Crenarchaeota;Nitrososphaeria;Nitrosopumilales;Nitrosopumilaceae;Candidatus Nitrosopumilus	0.9558707678091154</pre></td></tr><tr><td data-num="7"></td><td><pre>d62ab321b324b106e11961e79384f974	Bacteria;Methylomirabilota;Methylomirabilia;Methylomirabilales;Methylomirabilaceae;wb1-A12	0.9999999975860316</pre></td></tr><tr><td data-num="8"></td><td><pre>920aa9728ffb783cbc5721932cadda36	Bacteria;Aerophobota;Aerophobia;Aerophobales;uncultured bacterium	0.9999939600150409</pre></td></tr><tr><td data-num="9"></td><td><pre>b5edcefd9280528ee377cb70dea8a6a7	Archaea;Asgardarchaeota;Lokiarchaeia;uncultured archaeon	0.99744406884555</pre></td></tr><tr><td data-num="10"></td><td><pre>43b02d567fe419b94ad063081c7bba58	Bacteria;Planctomycetota;Brocadiae;Brocadiales;Scalinduaceae;Candidatus Scalindua;uncultured bacterium	0.9999941829048367</pre></td></tr><tr><td data-num="11"></td><td><pre>0f1be1121dd04bc63b5ec4be0efc09b8	Archaea;Asgardarchaeota;Lokiarchaeia;uncultured archaeon	0.7884239553020901</pre></td></tr><tr><td data-num="12"></td><td><pre>430d9115ca79bad01227bcc9c7694cf1	Bacteria;Proteobacteria;Gammaproteobacteria;Xanthomonadales;Xanthomonadaceae;Thermomonas;uncultured bacterium	0.7413321650122459</pre></td></tr><tr><td data-num="13"></td><td><pre>0bf08973da329747d913d5c261f91944	Bacteria;Aerophobota;Aerophobia;Aerophobales	1.0000000000000024</pre></td></tr></table></figure><ul><li>进化树，本教程中文件名为<strong> tree.nwk</strong>。该文件可由 QIIME2 生成，Newick 格式，是用代表序列构建的系统发育树。</li></ul><hr><h1 id="alpha-diversity"><a class="anchor" href="#alpha-diversity">#</a> Alpha diversity</h1><h2 id="shannon-richness-simpson-chao1-ace-pielou-pd_whole_tree指数的计算与可视化"><a class="anchor" href="#shannon-richness-simpson-chao1-ace-pielou-pd_whole_tree指数的计算与可视化">#</a> Shannon、Richness、Simpson、Chao1、ACE、Pielou、PD_whole_tree 指数的计算与可视化</h2><h3 id="输入文件"><a class="anchor" href="#输入文件">#</a> 输入文件</h3><ul><li>feature-table.tsv</li><li>sample-metadata.tsv</li></ul><h3 id="第一步计算多样性"><a class="anchor" href="#第一步计算多样性">#</a> 第一步：计算多样性</h3><p>将如下代码保存到文件”compute_alpha.R“中，并将程序与输入文件放在同一目录下。在终端中运行命令”Rscript compute_alpha.R“，得到输出文件”alpha.txt“。</p><figure class="highlight r"><figcaption data-lang="r"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token comment">#!/usr/bin/env R</span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token comment">#定义函数</span></pre></td></tr><tr><td data-num="3"></td><td><pre>library<span class="token punctuation">(</span>picante<span class="token punctuation">)</span>       <span class="token comment">#picante 包加载时默认同时加载 vegan</span></pre></td></tr><tr><td data-num="4"></td><td><pre> </pre></td></tr><tr><td data-num="5"></td><td><pre>alpha <span class="token operator">&lt;-</span> <span class="token keyword">function</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> tree <span class="token operator">=</span> <span class="token keyword">NULL</span><span class="token punctuation">,</span> base <span class="token operator">=</span> exp<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="6"></td><td><pre>        est <span class="token operator">&lt;-</span> estimateR<span class="token punctuation">(</span>x<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="7"></td><td><pre>        Richness <span class="token operator">&lt;-</span> est<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token punctuation">]</span></pre></td></tr><tr><td data-num="8"></td><td><pre>        Chao1 <span class="token operator">&lt;-</span> est<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token punctuation">]</span></pre></td></tr><tr><td data-num="9"></td><td><pre>        ACE <span class="token operator">&lt;-</span> est<span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token punctuation">]</span></pre></td></tr><tr><td data-num="10"></td><td><pre>        Shannon <span class="token operator">&lt;-</span> diversity<span class="token punctuation">(</span>x<span class="token punctuation">,</span> index <span class="token operator">=</span> <span class="token string">'shannon'</span><span class="token punctuation">,</span> base <span class="token operator">=</span> base<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="11"></td><td><pre>        Simpson <span class="token operator">&lt;-</span> diversity<span class="token punctuation">(</span>x<span class="token punctuation">,</span> index <span class="token operator">=</span> <span class="token string">'simpson'</span><span class="token punctuation">)</span>    <span class="token comment">#Gini-Simpson 指数</span></pre></td></tr><tr><td data-num="12"></td><td><pre>        Pielou <span class="token operator">&lt;-</span> Shannon <span class="token operator">/</span> log<span class="token punctuation">(</span>Richness<span class="token punctuation">,</span> base<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="13"></td><td><pre>        goods_coverage <span class="token operator">&lt;-</span> <span class="token number">1</span> <span class="token operator">-</span> rowSums<span class="token punctuation">(</span>x <span class="token operator">==</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">/</span> rowSums<span class="token punctuation">(</span>x<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="14"></td><td><pre>        </pre></td></tr><tr><td data-num="15"></td><td><pre>        result <span class="token operator">&lt;-</span> data.frame<span class="token punctuation">(</span>Richness<span class="token punctuation">,</span> Shannon<span class="token punctuation">,</span> Simpson<span class="token punctuation">,</span> Pielou<span class="token punctuation">,</span> Chao1<span class="token punctuation">,</span> ACE<span class="token punctuation">,</span> goods_coverage<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="16"></td><td><pre>        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>is.null<span class="token punctuation">(</span>tree<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="17"></td><td><pre>                PD_whole_tree <span class="token operator">&lt;-</span> pd<span class="token punctuation">(</span>x<span class="token punctuation">,</span> tree<span class="token punctuation">,</span> include.root <span class="token operator">=</span> <span class="token boolean">FALSE</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span></pre></td></tr><tr><td data-num="18"></td><td><pre>                names<span class="token punctuation">(</span>PD_whole_tree<span class="token punctuation">)</span> <span class="token operator">&lt;-</span> <span class="token string">'PD_whole_tree'</span></pre></td></tr><tr><td data-num="19"></td><td><pre>                result <span class="token operator">&lt;-</span> cbind<span class="token punctuation">(</span>result<span class="token punctuation">,</span> PD_whole_tree<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="20"></td><td><pre>        <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="21"></td><td><pre>        result</pre></td></tr><tr><td data-num="22"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="23"></td><td><pre> </pre></td></tr><tr><td data-num="24"></td><td><pre><span class="token comment">#现在直接使用定义好的命令 alpha ()，一步得到多种 Alpha 多样性指数</span></pre></td></tr><tr><td data-num="25"></td><td><pre><span class="token comment">#加载 OTU 丰度表和进化树文件</span></pre></td></tr><tr><td data-num="26"></td><td><pre>otu <span class="token operator">&lt;-</span> read.delim<span class="token punctuation">(</span><span class="token string">'feature-table.tsv'</span><span class="token punctuation">,</span> row.names <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span> sep <span class="token operator">=</span> <span class="token string">'\t'</span><span class="token punctuation">,</span> stringsAsFactors <span class="token operator">=</span> <span class="token boolean">FALSE</span><span class="token punctuation">,</span> check.names <span class="token operator">=</span> <span class="token boolean">FALSE</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="27"></td><td><pre>otu <span class="token operator">&lt;-</span> t<span class="token punctuation">(</span>otu<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="28"></td><td><pre>tree <span class="token operator">&lt;-</span> read.tree<span class="token punctuation">(</span><span class="token string">'tree.nwk'</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="29"></td><td><pre> </pre></td></tr><tr><td data-num="30"></td><td><pre><span class="token comment">#不包含谱系多样性，无需指定进化树；Shannon 公式的 log 底数我们使用 2</span></pre></td></tr><tr><td data-num="31"></td><td><pre><span class="token comment">##alpha_all &lt;- alpha(otu, base = 2)</span></pre></td></tr><tr><td data-num="32"></td><td><pre><span class="token comment">#包含谱系多样性时，指定进化树文件；Shannon 公式的 log 底数我们使用 2</span></pre></td></tr><tr><td data-num="33"></td><td><pre>alpha_all <span class="token operator">&lt;-</span> alpha<span class="token punctuation">(</span>otu<span class="token punctuation">,</span> tree<span class="token punctuation">,</span> base <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="34"></td><td><pre> </pre></td></tr><tr><td data-num="35"></td><td><pre><span class="token comment">#输出保存在本地</span></pre></td></tr><tr><td data-num="36"></td><td><pre>write.table<span class="token punctuation">(</span>alpha_all<span class="token punctuation">,</span> <span class="token string">'alpha.txt'</span><span class="token punctuation">,</span> sep<span class="token operator">=</span><span class="token string">"\t"</span><span class="token punctuation">,</span> quote <span class="token operator">=</span> <span class="token boolean">FALSE</span><span class="token punctuation">)</span></pre></td></tr></table></figure><h3 id="第二步制图"><a class="anchor" href="#第二步制图">#</a> 第二步：制图</h3><p>这一步需要在 Rstudio 中运行如下命令，在终端里直接运行会报错（莫名其妙），最终输出 7 个 PDF 图形文件。</p><figure class="highlight r"><figcaption data-lang="r"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token comment">#!/usr/bin/env R</span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token comment"># 基于 github 安装包，需要 devtools，检测是否存在，不存在则安装</span></pre></td></tr><tr><td data-num="3"></td><td><pre><span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>requireNamespace<span class="token punctuation">(</span><span class="token string">"devtools"</span><span class="token punctuation">,</span> quietly <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="4"></td><td><pre>    install.packages<span class="token punctuation">(</span><span class="token string">"devtools"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="5"></td><td><pre></pre></td></tr><tr><td data-num="6"></td><td><pre><span class="token comment"># 加载 github 包安装工具</span></pre></td></tr><tr><td data-num="7"></td><td><pre>library<span class="token punctuation">(</span>devtools<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="8"></td><td><pre></pre></td></tr><tr><td data-num="9"></td><td><pre><span class="token comment"># 检测 amplicon 包是否安装，没有从源码安装</span></pre></td></tr><tr><td data-num="10"></td><td><pre><span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>requireNamespace<span class="token punctuation">(</span><span class="token string">"amplicon"</span><span class="token punctuation">,</span> quietly <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="11"></td><td><pre>    install_github<span class="token punctuation">(</span><span class="token string">"liaochenlanruo/amplicon"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="12"></td><td><pre><span class="token comment"># 提示升级，选择 3 None 不升级；升级会容易出现报错</span></pre></td></tr><tr><td data-num="13"></td><td><pre></pre></td></tr><tr><td data-num="14"></td><td><pre><span class="token comment"># library 加载包，suppress 不显示消息和警告信息</span></pre></td></tr><tr><td data-num="15"></td><td><pre>suppressWarnings<span class="token punctuation">(</span>suppressMessages<span class="token punctuation">(</span>library<span class="token punctuation">(</span>amplicon<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="16"></td><td><pre></pre></td></tr><tr><td data-num="17"></td><td><pre><span class="token comment"># 设置工作目录，根据实际情况设定</span></pre></td></tr><tr><td data-num="18"></td><td><pre>setwd<span class="token punctuation">(</span><span class="token string">"用户自己的工作目录"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="19"></td><td><pre></pre></td></tr><tr><td data-num="20"></td><td><pre><span class="token comment"># 读取元数据，参数指定包括标题行 (TRUE)，列名为 1 列，制表符分隔，无注释行，不转换为因子类型</span></pre></td></tr><tr><td data-num="21"></td><td><pre>metadata <span class="token operator">=</span> read.table<span class="token punctuation">(</span><span class="token string">"sample-metadata.tsv"</span><span class="token punctuation">,</span> header<span class="token operator">=</span>T<span class="token punctuation">,</span> row.names<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">,</span> sep<span class="token operator">=</span><span class="token string">"\t"</span><span class="token punctuation">,</span> comment.char<span class="token operator">=</span><span class="token string">""</span><span class="token punctuation">,</span> stringsAsFactors <span class="token operator">=</span> F<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="22"></td><td><pre></pre></td></tr><tr><td data-num="23"></td><td><pre><span class="token comment"># 读取第一步中 vegan 计算的 6 种 alpha 多样性指数</span></pre></td></tr><tr><td data-num="24"></td><td><pre><span class="token comment">#alpha_div = read.table("alpha.txt", header=T, row.names=1, sep="\t", comment.char="")</span></pre></td></tr><tr><td data-num="25"></td><td><pre>alpha_div <span class="token operator">&lt;-</span> read.delim<span class="token punctuation">(</span><span class="token string">"alpha.txt"</span><span class="token punctuation">,</span> quote<span class="token operator">=</span><span class="token string">""</span><span class="token punctuation">,</span> stringsAsFactors<span class="token operator">=</span><span class="token boolean">FALSE</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="26"></td><td><pre></pre></td></tr><tr><td data-num="27"></td><td><pre><span class="token comment"># 绘制各组香农指数分布，外层 () 可对保存的图形同时预览</span></pre></td></tr><tr><td data-num="28"></td><td><pre><span class="token punctuation">(</span>p1 <span class="token operator">=</span> alpha_boxplot<span class="token punctuation">(</span>alpha_div<span class="token punctuation">,</span> index <span class="token operator">=</span> <span class="token string">"Shannon"</span><span class="token punctuation">,</span> metadata<span class="token punctuation">,</span> groupID <span class="token operator">=</span> <span class="token string">"Depth2"</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="29"></td><td><pre></pre></td></tr><tr><td data-num="30"></td><td><pre><span class="token comment">## 物种丰富度 Richness 指数</span></pre></td></tr><tr><td data-num="31"></td><td><pre><span class="token punctuation">(</span>p2 <span class="token operator">=</span> alpha_boxplot<span class="token punctuation">(</span>alpha_div<span class="token punctuation">,</span> index <span class="token operator">=</span> <span class="token string">"Richness"</span><span class="token punctuation">,</span> metadata<span class="token punctuation">,</span> groupID <span class="token operator">=</span> <span class="token string">"Depth2"</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="32"></td><td><pre></pre></td></tr><tr><td data-num="33"></td><td><pre><span class="token comment">#Gini-Simpson 指数（我们平时常用的 Simpson 指数即为 Gini-Simpson 指数）</span></pre></td></tr><tr><td data-num="34"></td><td><pre><span class="token punctuation">(</span>p3 <span class="token operator">=</span> alpha_boxplot<span class="token punctuation">(</span>alpha_div<span class="token punctuation">,</span> index <span class="token operator">=</span> <span class="token string">"Simpson"</span><span class="token punctuation">,</span> metadata<span class="token punctuation">,</span> groupID <span class="token operator">=</span> <span class="token string">"Depth2"</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="35"></td><td><pre></pre></td></tr><tr><td data-num="36"></td><td><pre><span class="token comment">#Chao1 指数</span></pre></td></tr><tr><td data-num="37"></td><td><pre><span class="token punctuation">(</span>p4 <span class="token operator">=</span> alpha_boxplot<span class="token punctuation">(</span>alpha_div<span class="token punctuation">,</span> index <span class="token operator">=</span> <span class="token string">"Chao1"</span><span class="token punctuation">,</span> metadata<span class="token punctuation">,</span> groupID <span class="token operator">=</span> <span class="token string">"Depth2"</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="38"></td><td><pre></pre></td></tr><tr><td data-num="39"></td><td><pre><span class="token comment">#ACE 指数</span></pre></td></tr><tr><td data-num="40"></td><td><pre><span class="token punctuation">(</span>p5 <span class="token operator">=</span> alpha_boxplot<span class="token punctuation">(</span>alpha_div<span class="token punctuation">,</span> index <span class="token operator">=</span> <span class="token string">"ACE"</span><span class="token punctuation">,</span> metadata<span class="token punctuation">,</span> groupID <span class="token operator">=</span> <span class="token string">"Depth2"</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="41"></td><td><pre></pre></td></tr><tr><td data-num="42"></td><td><pre><span class="token comment">#Shannon 均匀度（Pielou 均匀度）</span></pre></td></tr><tr><td data-num="43"></td><td><pre><span class="token punctuation">(</span>p6 <span class="token operator">=</span> alpha_boxplot<span class="token punctuation">(</span>alpha_div<span class="token punctuation">,</span> index <span class="token operator">=</span> <span class="token string">"Pielou"</span><span class="token punctuation">,</span> metadata<span class="token punctuation">,</span> groupID <span class="token operator">=</span> <span class="token string">"Depth2"</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="44"></td><td><pre></pre></td></tr><tr><td data-num="45"></td><td><pre><span class="token comment">## 谱系多样性</span></pre></td></tr><tr><td data-num="46"></td><td><pre><span class="token punctuation">(</span>p7 <span class="token operator">=</span> alpha_boxplot<span class="token punctuation">(</span>alpha_div<span class="token punctuation">,</span> index <span class="token operator">=</span> <span class="token string">"PD_whole_tree"</span><span class="token punctuation">,</span> metadata<span class="token punctuation">,</span> groupID <span class="token operator">=</span> <span class="token string">"Depth2"</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="47"></td><td><pre></pre></td></tr><tr><td data-num="48"></td><td><pre></pre></td></tr><tr><td data-num="49"></td><td><pre><span class="token comment"># 保存图片，指定图片为 pdf 格式方便后期修改，图片宽 89 毫米，高 75 毫米</span></pre></td></tr><tr><td data-num="50"></td><td><pre>ggsave<span class="token punctuation">(</span>paste0<span class="token punctuation">(</span><span class="token string">"alpha_boxplot_shannon.pdf"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> p1<span class="token punctuation">,</span> width<span class="token operator">=</span><span class="token number">89</span><span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token number">75</span><span class="token punctuation">,</span> units<span class="token operator">=</span><span class="token string">"mm"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="51"></td><td><pre>ggsave<span class="token punctuation">(</span>paste0<span class="token punctuation">(</span><span class="token string">"alpha_boxplot_Richness.pdf"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> p2<span class="token punctuation">,</span> width<span class="token operator">=</span><span class="token number">89</span><span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token number">75</span><span class="token punctuation">,</span> units<span class="token operator">=</span><span class="token string">"mm"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="52"></td><td><pre>ggsave<span class="token punctuation">(</span>paste0<span class="token punctuation">(</span><span class="token string">"alpha_boxplot_Simpson.pdf"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> p3<span class="token punctuation">,</span> width<span class="token operator">=</span><span class="token number">89</span><span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token number">75</span><span class="token punctuation">,</span> units<span class="token operator">=</span><span class="token string">"mm"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="53"></td><td><pre>ggsave<span class="token punctuation">(</span>paste0<span class="token punctuation">(</span><span class="token string">"alpha_boxplot_Chao1.pdf"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> p4<span class="token punctuation">,</span> width<span class="token operator">=</span><span class="token number">89</span><span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token number">75</span><span class="token punctuation">,</span> units<span class="token operator">=</span><span class="token string">"mm"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="54"></td><td><pre>ggsave<span class="token punctuation">(</span>paste0<span class="token punctuation">(</span><span class="token string">"alpha_boxplot_ACE.pdf"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> p5<span class="token punctuation">,</span> width<span class="token operator">=</span><span class="token number">89</span><span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token number">75</span><span class="token punctuation">,</span> units<span class="token operator">=</span><span class="token string">"mm"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="55"></td><td><pre>ggsave<span class="token punctuation">(</span>paste0<span class="token punctuation">(</span><span class="token string">"alpha_boxplot_Pielou.pdf"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> p6<span class="token punctuation">,</span> width<span class="token operator">=</span><span class="token number">89</span><span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token number">75</span><span class="token punctuation">,</span> units<span class="token operator">=</span><span class="token string">"mm"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="56"></td><td><pre>ggsave<span class="token punctuation">(</span>paste0<span class="token punctuation">(</span><span class="token string">"alpha_boxplot_PD_whole_tree.pdf"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> p7<span class="token punctuation">,</span> width<span class="token operator">=</span><span class="token number">89</span><span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token number">75</span><span class="token punctuation">,</span> units<span class="token operator">=</span><span class="token string">"mm"</span><span class="token punctuation">)</span></pre></td></tr></table></figure><h3 id="演示视频"><a class="anchor" href="#演示视频">#</a> 演示视频</h3><div style="position:relative;width:100%;height:0;padding-bottom:75%"><iframe src="//player.bilibili.com/player.html?aid=335536606&page=" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen style="position:absolute;width:100%;height:100%;left:0;top:0"></iframe></div><hr><h2 id="物种多样性条形图的绘制"><a class="anchor" href="#物种多样性条形图的绘制">#</a> 物种多样性条形图的绘制</h2><h3 id="输入文件-2"><a class="anchor" href="#输入文件-2">#</a> 输入文件</h3><ul><li>处理后的 Feature Table</li></ul><p>从 QIIME2 可视化网站上下载的各 level 的物种丰度表，此处以 level-2（Phylum 水平）为例，命名为 “level-2.csv”。该文件可以用 excel 或 WPS 打开，然后复制所有内容至一个新建的名字为 “level-2.txt” 的文本文档中，删除无关的行或列（如路径），只保留丰度数据，并保存。格式如下：</p><figure class="highlight tex"><figcaption data-lang="TeX"></figcaption><table><tr><td data-num="1"></td><td><pre>index	species1	species2	species3	species4</pre></td></tr><tr><td data-num="2"></td><td><pre>Sample1	0	8152	11	65</pre></td></tr><tr><td data-num="3"></td><td><pre>Sample2	12	97	1097	1315</pre></td></tr><tr><td data-num="4"></td><td><pre>...</pre></td></tr><tr><td data-num="5"></td><td><pre>Samplex	15	46	2928	1011</pre></td></tr></table></figure><ul><li>sample-metadata.tsv</li><li>taxonomy.tsv</li></ul><h3 id="绘图"><a class="anchor" href="#绘图">#</a> 绘图</h3><p>以下代码在 Rstudio 中逐步输入运行</p><figure class="highlight r"><figcaption data-lang="r"></figcaption><table><tr><td data-num="1"></td><td><pre>setwd<span class="token punctuation">(</span><span class="token string">"用户自己的路径"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="2"></td><td><pre></pre></td></tr><tr><td data-num="3"></td><td><pre><span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>requireNamespace<span class="token punctuation">(</span><span class="token string">"devtools"</span><span class="token punctuation">,</span> quietly<span class="token operator">=</span><span class="token boolean">TRUE</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="4"></td><td><pre>    install.packages<span class="token punctuation">(</span><span class="token string">"devtools"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="5"></td><td><pre>library<span class="token punctuation">(</span>devtools<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="6"></td><td><pre></pre></td></tr><tr><td data-num="7"></td><td><pre><span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>requireNamespace<span class="token punctuation">(</span><span class="token string">"amplicon"</span><span class="token punctuation">,</span> quietly<span class="token operator">=</span><span class="token boolean">TRUE</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="8"></td><td><pre>    install_github<span class="token punctuation">(</span><span class="token string">"microbiota/amplicon"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="9"></td><td><pre>suppressWarnings<span class="token punctuation">(</span>suppressMessages<span class="token punctuation">(</span>library<span class="token punctuation">(</span>amplicon<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="10"></td><td><pre></pre></td></tr><tr><td data-num="11"></td><td><pre><span class="token comment"># 从文件读取元数据，特征表和物种注释</span></pre></td></tr><tr><td data-num="12"></td><td><pre>metadata<span class="token operator">=</span>read.table<span class="token punctuation">(</span><span class="token string">"sample-metadata.tsv"</span><span class="token punctuation">,</span> header<span class="token operator">=</span>T<span class="token punctuation">,</span> row.names<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">,</span> sep<span class="token operator">=</span><span class="token string">"\t"</span><span class="token punctuation">,</span> comment.char<span class="token operator">=</span><span class="token string">""</span><span class="token punctuation">,</span> stringsAsFactors<span class="token operator">=</span>F<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="13"></td><td><pre></pre></td></tr><tr><td data-num="14"></td><td><pre>taxonomy<span class="token operator">=</span>read.table<span class="token punctuation">(</span><span class="token string">"taxonomy.tsv"</span><span class="token punctuation">,</span> header<span class="token operator">=</span>T<span class="token punctuation">,</span> row.names<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">,</span> sep<span class="token operator">=</span><span class="token string">"\t"</span><span class="token punctuation">,</span> comment.char<span class="token operator">=</span><span class="token string">""</span><span class="token punctuation">,</span> stringsAsFactors<span class="token operator">=</span>F<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="15"></td><td><pre></pre></td></tr><tr><td data-num="16"></td><td><pre>otutab2<span class="token operator">=</span>read.table<span class="token punctuation">(</span><span class="token string">"level-2.txt"</span><span class="token punctuation">,</span> header<span class="token operator">=</span>T<span class="token punctuation">,</span> row.names<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">,</span> sep<span class="token operator">=</span><span class="token string">"\t"</span><span class="token punctuation">,</span> comment.char<span class="token operator">=</span><span class="token string">""</span><span class="token punctuation">,</span> stringsAsFactors<span class="token operator">=</span>F<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="17"></td><td><pre></pre></td></tr><tr><td data-num="18"></td><td><pre><span class="token comment">#堆叠柱状图。以分组均值绘制，展示丰度最高的 19 个门，其余归类为其他 (Other)</span></pre></td></tr><tr><td data-num="19"></td><td><pre><span class="token comment"># 门水平物种组成表和元数据作为输入，分组列名为 Group，默认显示前 19 个分类，按丰度排序</span></pre></td></tr><tr><td data-num="20"></td><td><pre>otutab2<span class="token operator">=</span>t<span class="token punctuation">(</span>otutab2<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="21"></td><td><pre></pre></td></tr><tr><td data-num="22"></td><td><pre><span class="token punctuation">(</span>ps<span class="token operator">=</span>tax_stackplot<span class="token punctuation">(</span>otutab2<span class="token punctuation">,</span> metadata<span class="token punctuation">,</span> groupID<span class="token operator">=</span><span class="token string">"Site"</span><span class="token punctuation">,</span> topN<span class="token operator">=</span><span class="token number">20</span><span class="token punctuation">,</span> style<span class="token operator">=</span><span class="token string">"sample"</span><span class="token punctuation">,</span> sorted<span class="token operator">=</span><span class="token string">"abundance"</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="23"></td><td><pre></pre></td></tr><tr><td data-num="24"></td><td><pre>ps2 <span class="token operator">=</span> ps <span class="token operator">+</span> scale_fill_manual<span class="token punctuation">(</span>values <span class="token operator">=</span> rev<span class="token punctuation">(</span>c<span class="token punctuation">(</span><span class="token string">"#1f77b4"</span><span class="token punctuation">,</span> <span class="token string">"#aec7e8"</span><span class="token punctuation">,</span> <span class="token string">"#ff7f0e"</span><span class="token punctuation">,</span> <span class="token string">"#ffbb78"</span><span class="token punctuation">,</span> <span class="token string">"#2ca02c"</span><span class="token punctuation">,</span> <span class="token string">"#98df8a"</span><span class="token punctuation">,</span> <span class="token string">"#d62728"</span><span class="token punctuation">,</span> <span class="token string">"#ff9896"</span><span class="token punctuation">,</span> <span class="token string">"#9467bd"</span><span class="token punctuation">,</span> <span class="token string">"#c5b0d5"</span><span class="token punctuation">,</span> <span class="token string">"#8c564b"</span><span class="token punctuation">,</span> <span class="token string">"#c49c94"</span><span class="token punctuation">,</span> <span class="token string">"#e377c2"</span><span class="token punctuation">,</span> <span class="token string">"#f7b6d2"</span><span class="token punctuation">,</span> <span class="token string">"#7f7f7f"</span><span class="token punctuation">,</span> <span class="token string">"#c7c7c7"</span><span class="token punctuation">,</span> <span class="token string">"#bcbd22"</span><span class="token punctuation">,</span> <span class="token string">"#dbdb8d"</span><span class="token punctuation">,</span> <span class="token string">"#17becf"</span><span class="token punctuation">,</span> <span class="token string">"#9edae5"</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">+</span> theme<span class="token punctuation">(</span>axis.text.x <span class="token operator">=</span> element_text<span class="token punctuation">(</span>angle <span class="token operator">=</span> <span class="token number">90</span><span class="token punctuation">,</span> hjust <span class="token operator">=</span> <span class="token number">0.5</span><span class="token punctuation">,</span> vjust <span class="token operator">=</span> <span class="token number">0.5</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="25"></td><td><pre></pre></td></tr><tr><td data-num="26"></td><td><pre>ps2</pre></td></tr></table></figure><h3 id="演示视频-2"><a class="anchor" href="#演示视频-2">#</a> 演示视频</h3><div style="position:relative;width:100%;height:0;padding-bottom:75%"><iframe src="//player.bilibili.com/player.html?aid=633107204&page=" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen style="position:absolute;width:100%;height:100%;left:0;top:0"></iframe></div><hr><h1 id="beta多样性"><a class="anchor" href="#beta多样性">#</a> Beta 多样性</h1><h2 id="nmds分析及可视化"><a class="anchor" href="#nmds分析及可视化">#</a> NMDS 分析及可视化</h2><h3 id="输入文件-3"><a class="anchor" href="#输入文件-3">#</a> 输入文件</h3><ul><li>feature-table.tsv</li><li>sample-metadata.tsv</li></ul><h3 id="分析过程"><a class="anchor" href="#分析过程">#</a> 分析过程</h3><p>在 Rstudio 中运行如下代码：</p><figure class="highlight r"><figcaption data-lang="r"></figcaption><table><tr><td data-num="1"></td><td><pre>setwd<span class="token punctuation">(</span><span class="token string">"用户的工作目录"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="2"></td><td><pre>library<span class="token punctuation">(</span><span class="token string">"vegan"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="3"></td><td><pre></pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token comment"># 读取数据，一份 otu.table 文件和一份分组信息文件</span></pre></td></tr><tr><td data-num="5"></td><td><pre>otu <span class="token operator">&lt;-</span> read.table<span class="token punctuation">(</span><span class="token string">"feature-table.tsv"</span><span class="token punctuation">,</span>row.names<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">,</span> header<span class="token operator">=</span>T<span class="token punctuation">,</span>sep<span class="token operator">=</span><span class="token string">"\t"</span><span class="token punctuation">,</span>check.names<span class="token operator">=</span>F<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="6"></td><td><pre></pre></td></tr><tr><td data-num="7"></td><td><pre>design <span class="token operator">&lt;-</span> read.table<span class="token punctuation">(</span><span class="token string">"sample-metadata.tsv"</span><span class="token punctuation">,</span>header<span class="token operator">=</span>T<span class="token punctuation">,</span>sep<span class="token operator">=</span><span class="token string">"\t"</span><span class="token punctuation">,</span>row.names<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">,</span>check.names<span class="token operator">=</span>F<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="8"></td><td><pre></pre></td></tr><tr><td data-num="9"></td><td><pre><span class="token comment"># 数据调整为列名是 OTU，行名是样本名</span></pre></td></tr><tr><td data-num="10"></td><td><pre>otu<span class="token operator">=</span>t<span class="token punctuation">(</span>otu<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="11"></td><td><pre></pre></td></tr><tr><td data-num="12"></td><td><pre><span class="token comment"># 标准化，当然 method 有很多，可以通过？decostand 查看其它 method</span></pre></td></tr><tr><td data-num="13"></td><td><pre>vare.hel<span class="token operator">&lt;-</span>decostand<span class="token punctuation">(</span>otu<span class="token punctuation">,</span>method<span class="token operator">=</span><span class="token string">"hellinger"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="14"></td><td><pre></pre></td></tr><tr><td data-num="15"></td><td><pre><span class="token comment"># 计算 Bray-curtis 距离矩阵</span></pre></td></tr><tr><td data-num="16"></td><td><pre>vare.dis <span class="token operator">&lt;-</span> vegdist<span class="token punctuation">(</span>vare.hel<span class="token punctuation">,</span>method<span class="token operator">=</span><span class="token string">"bray"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="17"></td><td><pre></pre></td></tr><tr><td data-num="18"></td><td><pre><span class="token comment"># 使用 NMDS 的方法</span></pre></td></tr><tr><td data-num="19"></td><td><pre>vare.mds <span class="token operator">&lt;-</span> metaMDS<span class="token punctuation">(</span>vare.hel<span class="token punctuation">,</span>distance <span class="token operator">=</span> <span class="token string">"bray"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="20"></td><td><pre></pre></td></tr><tr><td data-num="21"></td><td><pre><span class="token comment"># 首先提取前两轴坐标</span></pre></td></tr><tr><td data-num="22"></td><td><pre>point <span class="token operator">=</span> scores<span class="token punctuation">(</span>vare.mds<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="23"></td><td><pre></pre></td></tr><tr><td data-num="24"></td><td><pre><span class="token comment"># 将分组文件和得分文件合并</span></pre></td></tr><tr><td data-num="25"></td><td><pre>index <span class="token operator">=</span> merge<span class="token punctuation">(</span>design<span class="token punctuation">,</span> point<span class="token punctuation">,</span>by<span class="token operator">=</span><span class="token string">"row.names"</span><span class="token punctuation">,</span>all<span class="token operator">=</span>F<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="26"></td><td><pre></pre></td></tr><tr><td data-num="27"></td><td><pre><span class="token comment"># 查看 Stress 值</span></pre></td></tr><tr><td data-num="28"></td><td><pre><span class="token comment"># Stress 值是反映模型合适程度的指标，NMDS 会多次打乱数据计算 Stress 值，直到找到最合适的模型，也就是最低的 Stress 值；理想状况下，Stress 值为 0，一般 Stress 值低于 0.1 较为合理。</span></pre></td></tr><tr><td data-num="29"></td><td><pre>vare.mds</pre></td></tr><tr><td data-num="30"></td><td><pre></pre></td></tr><tr><td data-num="31"></td><td><pre><span class="token comment"># Stress:     0.07498046 #记住这个数字，后面会打印在图中</span></pre></td></tr><tr><td data-num="32"></td><td><pre></pre></td></tr><tr><td data-num="33"></td><td><pre><span class="token comment"># 显着性检验；anosim 本质是基于排名的算法，更加适合 NMDS，这里基于元数据中的深度（Depth）计算</span></pre></td></tr><tr><td data-num="34"></td><td><pre>anosim.result<span class="token operator">&lt;-</span>anosim<span class="token punctuation">(</span>vare.dis<span class="token punctuation">,</span> design<span class="token operator">$</span>Depth<span class="token punctuation">,</span>permutations <span class="token operator">=</span><span class="token number">999</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="35"></td><td><pre></pre></td></tr><tr><td data-num="36"></td><td><pre>summary<span class="token punctuation">(</span>anosim.result<span class="token punctuation">)</span></pre></td></tr><tr><td data-num="37"></td><td><pre></pre></td></tr><tr><td data-num="38"></td><td><pre><span class="token comment"># ANOSIM statistic R: 0.8036 #记住这个数字，后面会打印在图中</span></pre></td></tr><tr><td data-num="39"></td><td><pre><span class="token comment">#       Significance: 0.001 #记住这个数字，后面会打印在图中</span></pre></td></tr><tr><td data-num="40"></td><td><pre></pre></td></tr><tr><td data-num="41"></td><td><pre><span class="token comment"># tiff 输出图形，适合大部分出版刊物，入门级别分辩率 300,18*14 的长宽；</span></pre></td></tr><tr><td data-num="42"></td><td><pre><span class="token comment">#tiff(file="beta_bray_NMDS.tiff", res = 300, compression ="none", width=180,height=140,units= "mm")</span></pre></td></tr><tr><td data-num="43"></td><td><pre></pre></td></tr><tr><td data-num="44"></td><td><pre><span class="token comment"># 在这里我选择输出为 PDF，后续可以进一步的编辑</span></pre></td></tr><tr><td data-num="45"></td><td><pre>pdf<span class="token punctuation">(</span>file<span class="token operator">=</span><span class="token string">"beta_bray_NMDS.pdf"</span><span class="token punctuation">,</span> width<span class="token operator">=</span><span class="token number">180</span><span class="token punctuation">,</span>height<span class="token operator">=</span><span class="token number">140</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="46"></td><td><pre></pre></td></tr><tr><td data-num="47"></td><td><pre><span class="token comment">#开始出图，代码如下：</span></pre></td></tr><tr><td data-num="48"></td><td><pre>library<span class="token punctuation">(</span><span class="token string">"ggplot2"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="49"></td><td><pre></pre></td></tr><tr><td data-num="50"></td><td><pre>p <span class="token operator">=</span> ggplot<span class="token punctuation">(</span>index<span class="token punctuation">,</span> aes<span class="token punctuation">(</span>x<span class="token operator">=</span>NMDS1<span class="token punctuation">,</span> y<span class="token operator">=</span>NMDS2<span class="token punctuation">,</span> color<span class="token operator">=</span>as.factor<span class="token punctuation">(</span>Depth<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">+</span></pre></td></tr><tr><td data-num="51"></td><td><pre>      geom_point<span class="token punctuation">(</span>size<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">)</span> <span class="token operator">+</span></pre></td></tr><tr><td data-num="52"></td><td><pre>     <span class="token comment">#scale_colour_manual (values = c ("red","blue", "green")) +# 这行代码是用于自定义颜色的，有几个组就用几个颜色，少于 3 个组的话不支持自定义</span></pre></td></tr><tr><td data-num="53"></td><td><pre>     labs<span class="token punctuation">(</span>x<span class="token operator">=</span>paste<span class="token punctuation">(</span><span class="token string">"NMDS1"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> y<span class="token operator">=</span>paste<span class="token punctuation">(</span><span class="token string">"NMDS2"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> title<span class="token operator">=</span><span class="token string">""</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="54"></td><td><pre></pre></td></tr><tr><td data-num="55"></td><td><pre><span class="token comment">#置信区间当然要加上，有三种方式，线条类型也可以更改。将上面得到的三个指标在图中更换 Stress，R，p。</span></pre></td></tr><tr><td data-num="56"></td><td><pre></pre></td></tr><tr><td data-num="57"></td><td><pre>p<span class="token operator">+</span>stat_ellipse<span class="token punctuation">(</span>type <span class="token operator">=</span> <span class="token string">"t"</span><span class="token punctuation">,</span> linetype <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">,</span> level <span class="token operator">=</span> <span class="token number">0.95</span><span class="token punctuation">,</span> show.legend <span class="token operator">=</span> <span class="token boolean">TRUE</span><span class="token punctuation">)</span><span class="token operator">+</span></pre></td></tr><tr><td data-num="58"></td><td><pre>    annotate<span class="token punctuation">(</span><span class="token string">"text"</span><span class="token punctuation">,</span>x<span class="token operator">=</span><span class="token operator">-</span><span class="token number">2.5</span><span class="token punctuation">,</span>y<span class="token operator">=</span><span class="token operator">-</span><span class="token number">1.25</span><span class="token punctuation">,</span>parse<span class="token operator">=</span><span class="token boolean">TRUE</span><span class="token punctuation">,</span>size<span class="token operator">=</span><span class="token number">4</span><span class="token punctuation">,</span>label<span class="token operator">=</span><span class="token string">"'R: '*0.8036"</span><span class="token punctuation">,</span>family<span class="token operator">=</span><span class="token string">"serif"</span><span class="token punctuation">,</span>fontface<span class="token operator">=</span><span class="token string">"italic"</span><span class="token punctuation">,</span>colour<span class="token operator">=</span><span class="token string">"darkred"</span><span class="token punctuation">,</span>hjust <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token operator">+</span></pre></td></tr><tr><td data-num="59"></td><td><pre>    annotate<span class="token punctuation">(</span><span class="token string">"text"</span><span class="token punctuation">,</span>x<span class="token operator">=</span><span class="token operator">-</span><span class="token number">2.5</span><span class="token punctuation">,</span>y<span class="token operator">=</span><span class="token operator">-</span><span class="token number">1.35</span><span class="token punctuation">,</span>parse<span class="token operator">=</span><span class="token boolean">TRUE</span><span class="token punctuation">,</span>size<span class="token operator">=</span><span class="token number">4</span><span class="token punctuation">,</span>label<span class="token operator">=</span><span class="token string">"'p: '*0.001"</span><span class="token punctuation">,</span>family<span class="token operator">=</span><span class="token string">"serif"</span><span class="token punctuation">,</span>fontface<span class="token operator">=</span><span class="token string">"italic"</span><span class="token punctuation">,</span>colour<span class="token operator">=</span><span class="token string">"darkred"</span><span class="token punctuation">,</span>hjust <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token operator">+</span></pre></td></tr><tr><td data-num="60"></td><td><pre>    annotate<span class="token punctuation">(</span><span class="token string">"text"</span><span class="token punctuation">,</span>x<span class="token operator">=</span><span class="token operator">-</span><span class="token number">2.5</span><span class="token punctuation">,</span>y<span class="token operator">=</span><span class="token operator">-</span><span class="token number">1.45</span><span class="token punctuation">,</span>parse<span class="token operator">=</span><span class="token boolean">TRUE</span><span class="token punctuation">,</span>size<span class="token operator">=</span><span class="token number">4</span><span class="token punctuation">,</span>label<span class="token operator">=</span><span class="token string">"'Stress: '*0.075"</span><span class="token punctuation">,</span>family<span class="token operator">=</span><span class="token string">"serif"</span><span class="token punctuation">,</span>fontface<span class="token operator">=</span><span class="token string">"italic"</span><span class="token punctuation">,</span>colour<span class="token operator">=</span><span class="token string">"darkred"</span><span class="token punctuation">,</span>hjust <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token operator">+</span> geom_point<span class="token punctuation">(</span>aes<span class="token punctuation">(</span>x<span class="token operator">=</span>NMDS1<span class="token punctuation">,</span> y<span class="token operator">=</span>NMDS2<span class="token punctuation">,</span> shape<span class="token operator">=</span>Site<span class="token punctuation">)</span><span class="token punctuation">,</span> size<span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token operator">+</span></pre></td></tr><tr><td data-num="61"></td><td><pre>	<span class="token comment">#scale_shape_manual (values = c (15, 19, 17))+# 这行代码是用于自定义形状的，有几个组就用几个形状，少于 3 个组的话不支持自定义</span></pre></td></tr><tr><td data-num="62"></td><td><pre>    theme_classic<span class="token punctuation">(</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="63"></td><td><pre></pre></td></tr><tr><td data-num="64"></td><td><pre>dev.off<span class="token punctuation">(</span><span class="token punctuation">)</span></pre></td></tr></table></figure><h3 id="演示视频-3"><a class="anchor" href="#演示视频-3">#</a> 演示视频</h3><div style="position:relative;width:100%;height:0;padding-bottom:75%"><iframe src="//player.bilibili.com/player.html?aid=548008577&page=" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen style="position:absolute;width:100%;height:100%;left:0;top:0"></iframe></div><h1 id="参考"><a class="anchor" href="#参考">#</a> 参考</h1><ul><li><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL1lvbmd4aW5MaXUvTWljcm9iaW9tZVN0YXRQbG90">https://github.com/YongxinLiu/MicrobiomeStatPlot</span></li></ul><p><font color="#FF0000"><ruby><b>敬告</b>：使用文中脚本请引用本文网址，请尊重本人的劳动成果，谢谢！<rt><b>Notice</b>: When you use the scripts in this article, please cite the link of this webpage. Thank you!</rt></ruby></font></p><div class="tags"><a href="/tags/%E6%89%A9%E5%A2%9E%E5%AD%90/" rel="tag"><i class="ic i-tag"></i> 扩增子</a> <a href="/tags/SY179/" rel="tag"><i class="ic i-tag"></i> SY179</a> <a href="/tags/R%E8%AF%AD%E8%A8%80/" rel="tag"><i class="ic i-tag"></i> R语言</a></div></div><footer><div class="meta"><span class="item"><span class="icon"><i class="ic i-calendar-check"></i> </span><span class="text">Edited on</span> <time title="Modified: 2022-05-31 09:41:33" itemprop="dateModified" datetime="2022-05-31T09:41:33+08:00">2022-05-31</time> </span><span id="post/fccc.html" class="item leancloud_visitors" data-flag-title="扩增子可视化专题" title="Views"><span class="icon"><i class="ic i-eye"></i> </span><span class="text">Views</span> <span class="leancloud-visitors-count"></span> <span class="text">times</span></span></div><div class="reward"><button><i class="ic i-heartbeat"></i> Donate</button><p>Give me a cup of [coffee]~(￣▽￣)~*</p><div id="qr"><div><img data-src="/images/reward-wepays.jpg" alt="Hualin Liu WeChat Pay"><p>WeChat Pay</p></div><div><img data-src="/images/AliPays.jpg" alt="Hualin Liu Alipay"><p>Alipay</p></div></div></div><div id="copyright"><ul><li class="author"><strong>Post author: </strong>liaochenlanruo <i class="ic i-at"><em>@</em></i>了尘兰若的小坑</li><li class="link"><strong>Post link: </strong><a href="https://liaochenlanruo.gitee.io/post/fccc.html" title="扩增子可视化专题">https://liaochenlanruo.gitee.io/post/fccc.html</a></li><li class="license"><strong>Copyright Notice: </strong>All articles in this blog are licensed under <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzQuMC9kZWVkLnpo"><i class="ic i-creative-commons"><em>(CC)</em></i>BY-NC-SA</span> unless stating additionally.</li></ul></div></footer></article></div><div class="post-nav"><div class="item left"><a href="/post/6e6b.html" itemprop="url" rel="prev" data-background-image="https:&#x2F;&#x2F;fastly.jsdelivr.net&#x2F;gh&#x2F;liaochenlanruo&#x2F;cdn@master&#x2F;img&#x2F;custom&#x2F;bgs&#x2F;thumb_3.webp" title="绘图自定义colors"><span class="type">Previous Post</span> <span class="category"><i class="ic i-flag"></i> 可视化</span><h3>绘图自定义colors</h3></a></div><div class="item right"><a href="/post/baf4.html" itemprop="url" rel="next" data-background-image="https:&#x2F;&#x2F;fastly.jsdelivr.net&#x2F;gh&#x2F;liaochenlanruo&#x2F;cdn@master&#x2F;img&#x2F;custom&#x2F;bgs&#x2F;thumb_79.webp" title="扩增子系之绘制物种分类堆叠图"><span class="type">Next Post</span> <span class="category"><i class="ic i-flag"></i> 可视化</span><h3>扩增子系之绘制物种分类堆叠图</h3></a></div></div><div class="wrap" id="comments"></div></div><div id="sidebar"><div class="inner"><div class="panels"><div class="inner"><div class="contents panel pjax" data-title="Contents"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%87%86%E5%A4%87%E6%95%B0%E6%8D%AE"><span class="toc-number">1.</span> <span class="toc-text">准备数据</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#alpha-diversity"><span class="toc-number">2.</span> <span class="toc-text">Alpha diversity</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#shannon-richness-simpson-chao1-ace-pielou-pd_whole_tree%E6%8C%87%E6%95%B0%E7%9A%84%E8%AE%A1%E7%AE%97%E4%B8%8E%E5%8F%AF%E8%A7%86%E5%8C%96"><span class="toc-number">2.1.</span> <span class="toc-text">Shannon、Richness、Simpson、Chao1、ACE、Pielou、PD_whole_tree 指数的计算与可视化</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BE%93%E5%85%A5%E6%96%87%E4%BB%B6"><span class="toc-number">2.1.1.</span> <span class="toc-text">输入文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%AC%AC%E4%B8%80%E6%AD%A5%E8%AE%A1%E7%AE%97%E5%A4%9A%E6%A0%B7%E6%80%A7"><span class="toc-number">2.1.2.</span> <span class="toc-text">第一步：计算多样性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%AC%AC%E4%BA%8C%E6%AD%A5%E5%88%B6%E5%9B%BE"><span class="toc-number">2.1.3.</span> <span class="toc-text">第二步：制图</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%BC%94%E7%A4%BA%E8%A7%86%E9%A2%91"><span class="toc-number">2.1.4.</span> <span class="toc-text">演示视频</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%89%A9%E7%A7%8D%E5%A4%9A%E6%A0%B7%E6%80%A7%E6%9D%A1%E5%BD%A2%E5%9B%BE%E7%9A%84%E7%BB%98%E5%88%B6"><span class="toc-number">2.2.</span> <span class="toc-text">物种多样性条形图的绘制</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BE%93%E5%85%A5%E6%96%87%E4%BB%B6-2"><span class="toc-number">2.2.1.</span> <span class="toc-text">输入文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BB%98%E5%9B%BE"><span class="toc-number">2.2.2.</span> <span class="toc-text">绘图</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%BC%94%E7%A4%BA%E8%A7%86%E9%A2%91-2"><span class="toc-number">2.2.3.</span> <span class="toc-text">演示视频</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#beta%E5%A4%9A%E6%A0%B7%E6%80%A7"><span class="toc-number">3.</span> <span class="toc-text">Beta 多样性</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#nmds%E5%88%86%E6%9E%90%E5%8F%8A%E5%8F%AF%E8%A7%86%E5%8C%96"><span class="toc-number">3.1.</span> <span class="toc-text">NMDS 分析及可视化</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BE%93%E5%85%A5%E6%96%87%E4%BB%B6-3"><span class="toc-number">3.1.1.</span> <span class="toc-text">输入文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E6%9E%90%E8%BF%87%E7%A8%8B"><span class="toc-number">3.1.2.</span> <span class="toc-text">分析过程</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%BC%94%E7%A4%BA%E8%A7%86%E9%A2%91-3"><span class="toc-number">3.1.3.</span> <span class="toc-text">演示视频</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%8F%82%E8%80%83"><span class="toc-number">4.</span> <span class="toc-text">参考</span></a></li></ol></div><div class="related panel pjax" data-title="Related"><ul><li><a href="/post/f94b.html" rel="bookmark" title="R语言自定义坐标轴排序">R语言自定义坐标轴排序</a></li><li><a href="/post/6e6b.html" rel="bookmark" title="绘图自定义colors">绘图自定义colors</a></li><li class="active"><a href="/post/fccc.html" rel="bookmark" title="扩增子可视化专题">扩增子可视化专题</a></li><li><a href="/post/baf4.html" rel="bookmark" title="扩增子系之绘制物种分类堆叠图">扩增子系之绘制物种分类堆叠图</a></li><li><a href="/post/b68c.html" rel="bookmark" title="R语言绘制气泡图Bubb_Plot">R语言绘制气泡图Bubb_Plot</a></li></ul></div><div class="overview panel" data-title="Overview"><div class="author" itemprop="author" itemscope itemtype="http://schema.org/Person"><img class="image" itemprop="image" alt="Hualin Liu" data-src="/images/head.jpg"><p class="name" itemprop="name">Hualin Liu</p><div class="description" itemprop="description">分享微生物生物信息学分析方法，欢迎加入QQ群交流945751012，不接受群内广告！</div></div><nav class="state"><div class="item posts"><a href="/archives/"><span class="count">130</span> <span class="name">posts</span></a></div><div class="item categories"><a href="/categories/"><span class="count">12</span> <span class="name">categories</span></a></div><div class="item tags"><a href="/tags/"><span class="count">54</span> <span class="name">tags</span></a></div></nav><div class="social"><span class="exturl item github" data-url="aHR0cDovL2dpdGh1Yi5jb20vbGlhb2NoZW5sYW5ydW8=" title="http:&#x2F;&#x2F;github.com&#x2F;liaochenlanruo"><i class="ic i-github"></i></span> <span class="exturl item zhihu" data-url="aHR0cHM6Ly93d3cuemhpaHUuY29tL3Blb3BsZS9zdWFuLWxhLW1pYW4tcGlhbi10YW5nLWNpdW0=" title="https:&#x2F;&#x2F;www.zhihu.com&#x2F;people&#x2F;suan-la-mian-pian-tang-cium"><i class="ic i-zhihu"></i></span> <span class="exturl item weibo" data-url="aHR0cHM6Ly93ZWliby5jb20vdS8yNzE1MjEwOTIz" title="https:&#x2F;&#x2F;weibo.com&#x2F;u&#x2F;2715210923"><i class="ic i-weibo"></i></span> <span class="exturl item about" data-url="aHR0cHM6Ly93d3cubGlhb2NoZW5sYW5ydW8uZnVuL2Fib3V0" title="https:&#x2F;&#x2F;www.liaochenlanruo.fun&#x2F;about"><i class="ic i-address-card"></i></span> <span class="exturl item email" data-url="bWFpbHRvOmxpYW9jaGVubGFucnVvQHdlYm1haWwuaHphdS5lZHUuY24=" title="mailto:liaochenlanruo@webmail.hzau.edu.cn"><i class="ic i-envelope"></i></span> <span class="exturl item douban" data-url="aHR0cHM6Ly93d3cuZG91YmFuLmNvbS9wZW9wbGUvbGlhb2NoZW5sYW5ydW8vP19pPTczNDYxMjVRalo1QjZWLw==" title="https:&#x2F;&#x2F;www.douban.com&#x2F;people&#x2F;liaochenlanruo&#x2F;?_i&#x3D;7346125QjZ5B6V&#x2F;"><i class="ic i-douban"></i></span> <span class="exturl item google" data-url="aHR0cHM6Ly9zY2hvbGFyLmdvb2dsZS5jby5qcC9jaXRhdGlvbnM/dXNlcj1YYW9STk1RQUFBQUomaGw9amE=" title="https:&#x2F;&#x2F;scholar.google.co.jp&#x2F;citations?user&#x3D;XaoRNMQAAAAJ&amp;hl&#x3D;ja"><i class="ic i-google"></i></span></div><ul class="menu"><li class="item"><a href="/" rel="section"><i class="ic i-home"></i>Home</a></li><li class="item dropdown"><a href="javascript:void(0);"><i class="ic i-user"></i>About</a><ul class="submenu"><li class="item"><a href="/about/" rel="section"><i class="ic i-user"></i>About me</a></li><li class="item"><a href="/comment/" rel="section"><i class="ic i-envelope"></i>Comment</a></li></ul></li><li class="item dropdown"><a href="javascript:void(0);"><i class="ic i-feather"></i>Posts</a><ul class="submenu"><li class="item"><a href="/archives/" rel="section"><i class="ic i-list-alt"></i>Archives</a></li><li class="item"><a href="/categories/" rel="section"><i class="ic i-th"></i>Categories</a></li><li class="item"><a href="/tags/" rel="section"><i class="ic i-tags"></i>Tags</a></li></ul></li><li class="item dropdown"><a href="javascript:void(0);"><i class="ic i-list-ol"></i>List</a><ul class="submenu"><li class="item"><a href="/photos/" rel="section"><i class="ic i-person"></i>Photos</a></li><li class="item"><a href="/skip/gallery/" rel="section"><i class="ic i-cloud"></i>Gallery</a></li><li class="item"><a href="/skip/box/" rel="section"><i class="ic i-magic"></i>Box</a></li><li class="item"><span class="exturl" data-url="aHR0cHM6Ly9saWFvY2hlbmxhbnJ1by5mdW4vcmVmZXJlbmNlLw=="><i class="ic i-th"></i>cheatsheets</span></li></ul></li><li class="item"><a href="/donate/" rel="section"><i class="ic i-coffee"></i>Donate</a></li><li class="item"><a href="/friends/" rel="section"><i class="ic i-heart"></i>Friends</a></li><li class="item"><span class="exturl" data-url="aHR0cHM6Ly9saWFvY2hlbmxhbnJ1by5naXRodWIuaW8="><i class="ic i-external-link-alt"></i>中文版</span></li><li class="item"><span class="exturl" data-url="aHR0cHM6Ly90cmF2ZWxsaW5ncy5saW5r"><i class="ic i-forward"></i>Travelling</span></li></ul></div></div></div><ul id="quick"><li class="prev pjax"><a href="/post/6e6b.html" rel="prev" title="Previous Post"><i class="ic i-chevron-left"></i></a></li><li class="up"><i class="ic i-arrow-up"></i></li><li class="down"><i class="ic i-arrow-down"></i></li><li class="next pjax"><a href="/post/baf4.html" rel="next" title="Next Post"><i class="ic i-chevron-right"></i></a></li><li class="percent"></li></ul></div></div><div class="dimmer"></div></div></main><footer id="footer"><div class="inner"><div class="widgets"></div><div class="status"><div class="copyright">&copy; 2018 – <span itemprop="copyrightYear">2024</span> <span class="with-love"><i class="ic i-sakura rotate"></i> </span><span class="author" itemprop="copyrightHolder">Hualin Liu @ ResearchGo</span></div><div class="count"><span class="post-meta-item-icon"><i class="ic i-chart-area"></i> </span><span title="Symbols count total">788k words</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="ic i-coffee"></i> </span><span title="Reading time total">11:57</span><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="ic i-info-circle"></i> </span><span style="padding-left:1px"><span id="busuanzi_container_site_pv">Total visits: <span id="busuanzi_value_site_pv" style="color:#f99"></span> times</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="ic i-user"></i> </span><span style="padding-left:1px"><span id="busuanzi_container_site_uv">Total visitors: <span id="busuanzi_value_site_uv" style="color:#f99"></span> people</span></span></span></div><div class="powered-by">Powered by <span class="exturl" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> & Theme.<span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2FtZWhpbWUvaGV4by10aGVtZS1zaG9rYQ==">Shoka</span></div></div></div></footer></div><script data-config type="text/javascript">var LOCAL={path:"post/fccc.html",favicon:{show:"（●´3｀●）Goooood",hide:"(´Д｀)Booooom"},search:{placeholder:"Search for Posts",empty:"We didn't find any results for the search: ${query}",stats:"${hits} results found in ${time} ms"},valine:!0,fancybox:!0,copyright:'Copied to clipboard successfully! <br> All articles in this blog are licensed under <i class="ic i-creative-commons"></i>BY-NC-SA.',ignores:[function(e){return e.includes("#")},function(e){return new RegExp(LOCAL.path+"$").test(e)}]}</script><script src="https://cdn.polyfill.io/v2/polyfill.js"></script><script src="//cdn.jsdelivr.net/combine/npm/pace-js@1.0.2/pace.min.js,npm/pjax@0.2.8/pjax.min.js,npm/whatwg-fetch@3.4.0/dist/fetch.umd.min.js,npm/animejs@3.2.0/lib/anime.min.js,npm/algoliasearch@4/dist/algoliasearch-lite.umd.js,npm/instantsearch.js@4/dist/instantsearch.production.min.js,npm/lozad@1/dist/lozad.min.js,npm/quicklink@2/dist/quicklink.umd.js"></script><script src="/js/app.js?v=0.2.5"></script><script data-pjax>var _hmt=_hmt||[];!function(){var e=document.createElement("script");e.src="https://hm.baidu.com/hm.js?d211830a796ceefb38a141fde14e4d5a";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}()</script></body></html>